#include "../TcpServer.hpp"

void OnEstablished(const ConnPtr &conn) 
{
    DLOG("NEW CONNECTION:%p", conn.get());
}
void OnClose(const ConnPtr &conn) 
{
    DLOG("CLOSE CONNECTION:%p", conn.get());
}
void OnMessage(const ConnPtr &conn, Buffer *buf) 
{
    DLOG("%s", buf->ReadAddress());
    buf->MoveReadIdx(buf->ReadableSize());
    std::string str = "Hello World";
    conn->Send(str.c_str(), str.size());
    // conn->Shutdown();
}
int main()
{
    TcpServer server(8080);
    server.SetThreadCount(2);
    // server.OpenInactiveRelease(10);
    server.SetEstablishedCallBack(OnEstablished);//这里不需要bind，server内部调用的时候，会自动传好参数
    server.SetCloseCallBack(OnClose);
    server.SetMessageCallBack(OnMessage);
    server.Run();
    return 0;
}